﻿using ImageDefine;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ImageToolCircle
{
    [Serializable]
    public class ImageToolCircle : ImageToolBase,IPoint,ICircleTool
    {
        public ToolSetting Setting;
        public string strTraceName;
        public double dRadius;
        [NonSerialized]
        public ImageActionerCircle actioner;
        public ImageToolCircle() : base()
        {
            Setting = new ToolSetting();
            strTraceName = "";
        }
        public ImageToolCircle(ImageToolBase imageBase) : base(imageBase)
        {
            Setting = new ToolSetting();
            strTraceName = "";
        }
        override public void CreateActioner(ImageTask imageTaskIn)
        {
            imageTask = imageTaskIn;
            OutPutResults = new Dictionary<string, string>();
            strTaskName = imageTask.Name;
            actioner = new ImageActionerCircle(this);
        }
        override public void Run(HalconDotNet.HImage hImage, SmartDisplayControl.SmartDisplayControl smartDisplay)
        {
            actioner.Run(hImage, smartDisplay);
        }

        public static ImageToolTypeInfo ToolTypeRegister()
        {
            ImageToolTypeInfo imageToolTypeInfo = new ImageToolTypeInfo();
            imageToolTypeInfo.ToolName = "圆圈工具";
            imageToolTypeInfo.toolType = typeof(ImageToolCircle);
            return imageToolTypeInfo;
        }
        public override Form ShowSettingFrm()
        {
            FormSetting formSetting = new FormSetting(imageTask, this, actioner);
            return formSetting;
        }

        public bool GetPoint(out double dResultX, out double dResultY)
        {
            dResultX = this.ResultX;
            dResultY = this.ResultY;
            return bResultOK;
        }

        public bool GetCircle(out double dCenterX, out double dCenterY, out double dRadius)
        {
            dCenterX = this.ResultX;
            dCenterY = this.ResultY;
            dRadius = this.dRadius;
            return bResultOK;
        }

        public bool GetPoint(out double dResultX, out double dResultY, int iIndex)
        {
            dResultX = this.ImageToolResults[iIndex].ResultX;
            dResultY = this.ImageToolResults[iIndex].ResultY;
            return bResultOK;
        }

        public bool GetCircle(out double dCenterX, out double dCenterY, out double dRadius, int iIndex)
        {
            ImageResultCircle imageToolResultCircle = ImageToolResults[iIndex] as ImageResultCircle;
            dCenterX = imageToolResultCircle.ResultX;
            dCenterY = imageToolResultCircle.ResultY;
            dRadius = imageToolResultCircle.CircleR;
         

            return imageToolResultCircle.Result; ;
        }
    }
}
